﻿using PwjCy.Lite.EntityLite.Imp;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;

namespace PwjCy.Lite.Common
{
    /// <summary>
    /// List对象帮助类
    /// </summary>
    public sealed class ListHelper
    {
        /// <summary>
        /// DataRow转成PwjCyObject对象
        /// </summary>
        /// <param name="row"></param>
        /// <param name="t"></param>
        /// <returns></returns>
        public static object DataRow2PwjCyObject(DataRow row, Type t)
        {
            object obj = Activator.CreateInstance(t);
            foreach (var pi in EntityLiteRelationMap.Instance.PwjCyOjbectTypeDescription(t).PwjCyFields)
            {
                if (pi.CanWrite && row[pi.Name] != DBNull.Value)
                {
                    pi.SetValue(obj, TypeHelper.Instance.ChangeType(pi.PropertyType, row[pi.Name]), null);
                }
            }
            return obj;
        }
    }
}
